#include "dlg_login.h"
#include "ui_dlg_login.h"

Dlg_login::Dlg_login(QWidget *parent)
    : QDialog(parent)
    , ui(new Ui::Dlg_login)
    ,ptrstumysql(nullptr)
{
    ui->setupUi(this);
    ptrstumysql=Sqlmgr::getinstance();
}

Dlg_login::~Dlg_login()
{
    delete ui;
}

void Dlg_login::on_btn_login_clicked()
{
    QString strusername=ui->le_user->text();//获取输入的用户名
    QString strpassword=ui->le_password->text();//获取输入的密码
    int userid=0;
    bool ok=ptrstumysql->login(strusername,strpassword,userid);
    if(ok)
    {
        emit sendLoginname(strusername);
        QMessageBox::information(NULL,"登录","登录成功");
        setResult(1);
        hide();//登录成功后隐藏登录对话框，hide()就是隐藏对话框
    }
    else
    {
        QMessageBox::information(NULL,"登录","登录失败");
    }

}


void Dlg_login::on_bt_exit_clicked()
{
    //exit(0);
    setResult(0);   //这句话也是退出
    hide();
}

